﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace book_management_system
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        SqlConnection Con = new SqlConnection(@"Data Source=Kami;Initial Catalog=WhiteBookShopDb;Integrated Security=True");//连接或打开


        public static string UserName = "";//全局变量的用户名，用来显示

        private void ULogiTb_Click(object sender, EventArgs e)//登录按钮事件
        {
            Con.Open();
            SqlDataAdapter sda = new SqlDataAdapter("select count(*) from UserTb1 where UName = '"+UNameTb.Text+"' and UPassword = '"+UPassTb.Text+"'",Con);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            if (dt.Rows[0][0].ToString() == "1")
            {
                UserName = UNameTb.Text;//当输入用户是系统用户时就给全局变量用户名赋值
                Billing obj = new Billing();//用户是进入结算界面
                obj.Show();//进入Books界面
                this.Hide();//隐藏登录界面
                Con.Close();
            }
            else
            {
                MessageBox.Show("用户名或密码错误!!!");
            }

            Con.Close();
        }

        private void ExitBtn_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void Adminlab_Click(object sender, EventArgs e)
        {
            AdminLogin obj = new AdminLogin();
            obj.Show();
            this.Hide();
        }
    }
}
